package basic;
/**
 * This class implements a queue of customers as a circular buffer.
 */
public class CustomerQueue {
	private int head, tail;
	
	private Customer[] chairs = null;
	private final Gui gui;

	private final int queueLength;
	
	/**
	 * Creates a new customer queue.
	 * @param queueLength	The maximum length of the queue.
	 * @param gui			A reference to the GUI interface.
	 */
    public CustomerQueue(int queueLength, Gui gui) {
		this.queueLength = queueLength;
		this.gui = gui;
		// Incomplete
    	chairs = new Customer[queueLength];
	}
    
    public synchronized void addToQuee(Customer c){
    	// TODO
    	if(chairs[head] == null){
    		chairs[head] = c;
    		gui.fillLoungeChair(head, c);
    		gui.println("Kunde " + c.getCustomerID() + " venter i stol: " + head);
    		head = (head + 1 ) % queueLength;  
    		notifyAll();
    	}
    	
    }
    
    public synchronized Customer removeFromQuee(){
    	
    	Customer c = chairs[tail];
    	if (chairs[tail] != null) {
    		gui.emptyLoungeChair(tail);
    		gui.println("Kunde: " + c.getCustomerID() +" fjernes fra venting til barbering: " + head);
			chairs[tail] = null;
    		tail = (tail + 1) % queueLength;
			notifyAll();
		}
    	
    	return c;
    }

	// Add more methods as needed
}
